import request from '@/utils/request'

// 授权状态接口
export interface AuthStatus {
    is_authorized: boolean
    corp_id?: string
    corp_name?: string
    agent_id?: string
    auth_time?: string
    admin_name?: string
    admin_userid?: string
    scope?: string[]
    expires_at?: string
}

// 授权详情接口
export interface AuthDetail {
    corp_id: string
    corp_name: string
    corp_full_name?: string
    corp_type?: string
    corp_round_logo_url?: string
    corp_square_logo_url?: string
    agent_id: string
    suite_id?: string
    auth_time: string
    permanent_code?: string
    admin_name: string
    admin_userid: string
    admin_avatar?: string
    scope: string[]
    expires_at?: string
    auth_user_info?: {
        userid: string
        name: string
        avatar?: string
        department?: number[]
    }
}

// 获取当前授权状态
export const getAuthStatus = () => {
    return request.get({
        url: '/kefu.auth/info'
    })
}

// 获取授权详情
export const getAuthDetail = () => {
    return request.get({
        url: '/auth/detail'
    })
}

// 获取授权安装二维码
export const getAuthQRCode = () => {
    return request.get({
        url: '/kefu.auth/qrcode'
    })
}

// 刷新授权二维码
export const refreshAuthQRCode = () => {
    return request.post({
        url: '/auth/qrcode/refresh'
    })
}

// 取消授权
export const cancelAuth = () => {
    return request.post({
        url: '/auth/cancel'
    })
}

//解除授权
export const removeAuth = () => {
    let res = request.post({
        url: '/kefu.auth/remove'
    })
    console.log(res);
    return res;
}

// 检查授权状态（轮询用）
export const checkAuthStatus = () => {
    return request.get({
        url: '/kefu.auth/check'
    })
} 